/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * KeeperResults.java
 *
 * Created on 18 Απρ 2011, 7:32:58 μμ
 */
package tools.misc.housekeeping;

import java.util.Iterator;
import java.util.logging.Level;
import myComponents.myGUI.MyDraggable;
import tools.MySeriesLogger;
import tools.Skin;

/**
 *
 * @author ssoldatos
 */
public class KeeperResults extends MyDraggable {

  private static final long serialVersionUID = 232325252525L;
  private final HouseKeeper k;
  private int torrentsDel = 0;
  private int logsDel = 0;
  private int screenshotsDel = 0;
  private int torrentsNotDel = 0;
  private int logsNotDel = 0;
  private int screenshotsNotDel = 0;

  /** Creates new form KeeperResults */
  public KeeperResults(HouseKeeper k) {
    this.k = k;
    MySeriesLogger.logger.log(Level.INFO, "Showing housekeeping results");
    MySeriesLogger.logger.log(Level.INFO, "Initializing components");
    initComponents();
    MySeriesLogger.logger.log(Level.FINE, "Components initialized");
    getResults();
    showResults();
    setLocationRelativeTo(null);
    setVisible(true);

  }

  /** This method is called from within the constructor to
   * initialize the form.
   * WARNING: Do NOT modify this code. The content of this method is
   * always regenerated by the Form Editor.
   */
  @SuppressWarnings("unchecked")
  // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
  private void initComponents() {

    outer = new javax.swing.JPanel();
    inner = new javax.swing.JPanel();
    lb_torrents = new javax.swing.JLabel();
    lb_logs = new javax.swing.JLabel();
    lb_screenhsots = new javax.swing.JLabel();
    lb_torrentsResults = new javax.swing.JLabel();
    lb_logsResults = new javax.swing.JLabel();
    lb_screenshotsResults = new javax.swing.JLabel();
    jLabel1 = new javax.swing.JLabel();
    myButtonCancel1 = new myComponents.myGUI.buttons.MyButtonCancel();

    setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);

    outer.setBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(0, 0, 0)));

    inner.setBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(0, 0, 0)));
    inner.setOpaque(false);

    lb_torrents.setHorizontalAlignment(javax.swing.SwingConstants.RIGHT);
    lb_torrents.setText("Torrents deleted :");

    lb_logs.setHorizontalAlignment(javax.swing.SwingConstants.RIGHT);
    lb_logs.setText("Logs deleted :");

    lb_screenhsots.setHorizontalAlignment(javax.swing.SwingConstants.RIGHT);
    lb_screenhsots.setText("Screenshots deleted :");

    lb_torrentsResults.setHorizontalAlignment(javax.swing.SwingConstants.RIGHT);
    lb_torrentsResults.setText("0/0");

    lb_logsResults.setHorizontalAlignment(javax.swing.SwingConstants.RIGHT);
    lb_logsResults.setText("0/0");

    lb_screenshotsResults.setHorizontalAlignment(javax.swing.SwingConstants.RIGHT);
    lb_screenshotsResults.setText("0/0");

    javax.swing.GroupLayout innerLayout = new javax.swing.GroupLayout(inner);
    inner.setLayout(innerLayout);
    innerLayout.setHorizontalGroup(
      innerLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
      .addGroup(innerLayout.createSequentialGroup()
        .addContainerGap()
        .addGroup(innerLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
          .addComponent(lb_torrents, javax.swing.GroupLayout.DEFAULT_SIZE, 125, Short.MAX_VALUE)
          .addComponent(lb_logs, javax.swing.GroupLayout.DEFAULT_SIZE, 125, Short.MAX_VALUE)
          .addComponent(lb_screenhsots, javax.swing.GroupLayout.DEFAULT_SIZE, 125, Short.MAX_VALUE))
        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
        .addGroup(innerLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
          .addComponent(lb_torrentsResults, javax.swing.GroupLayout.PREFERRED_SIZE, 48, javax.swing.GroupLayout.PREFERRED_SIZE)
          .addComponent(lb_logsResults, javax.swing.GroupLayout.PREFERRED_SIZE, 48, javax.swing.GroupLayout.PREFERRED_SIZE)
          .addComponent(lb_screenshotsResults, javax.swing.GroupLayout.PREFERRED_SIZE, 48, javax.swing.GroupLayout.PREFERRED_SIZE))
        .addGap(127, 127, 127))
    );
    innerLayout.setVerticalGroup(
      innerLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
      .addGroup(innerLayout.createSequentialGroup()
        .addContainerGap()
        .addGroup(innerLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
          .addGroup(innerLayout.createSequentialGroup()
            .addComponent(lb_torrentsResults)
            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
            .addGroup(innerLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
              .addComponent(lb_logsResults)
              .addComponent(lb_logs))
            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
            .addGroup(innerLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
              .addComponent(lb_screenshotsResults)
              .addComponent(lb_screenhsots)))
          .addComponent(lb_torrents))
        .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
    );

    jLabel1.setFont(jLabel1.getFont().deriveFont(jLabel1.getFont().getStyle() | java.awt.Font.BOLD, jLabel1.getFont().getSize()+2));
    jLabel1.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
    jLabel1.setText("Housekeeping");

    myButtonCancel1.addActionListener(new java.awt.event.ActionListener() {
      public void actionPerformed(java.awt.event.ActionEvent evt) {
        myButtonCancel1ActionPerformed(evt);
      }
    });

    javax.swing.GroupLayout outerLayout = new javax.swing.GroupLayout(outer);
    outer.setLayout(outerLayout);
    outerLayout.setHorizontalGroup(
      outerLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
      .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, outerLayout.createSequentialGroup()
        .addGap(37, 37, 37)
        .addComponent(jLabel1, javax.swing.GroupLayout.DEFAULT_SIZE, 265, Short.MAX_VALUE)
        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
        .addComponent(myButtonCancel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
      .addGroup(outerLayout.createSequentialGroup()
        .addContainerGap()
        .addComponent(inner, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
        .addGap(10, 10, 10))
    );
    outerLayout.setVerticalGroup(
      outerLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
      .addGroup(outerLayout.createSequentialGroup()
        .addGroup(outerLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.CENTER)
          .addComponent(myButtonCancel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
          .addComponent(jLabel1))
        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
        .addComponent(inner, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
        .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
    );

    javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
    getContentPane().setLayout(layout);
    layout.setHorizontalGroup(
      layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
      .addComponent(outer, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
    );
    layout.setVerticalGroup(
      layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
      .addComponent(outer, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
    );

    pack();
  }// </editor-fold>//GEN-END:initComponents

  private void myButtonCancel1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_myButtonCancel1ActionPerformed
    MySeriesLogger.logger.log(Level.INFO, "Closing window");
    dispose();
    myseriesproject.MySeries.glassPane.deactivate();
  }//GEN-LAST:event_myButtonCancel1ActionPerformed

  // Variables declaration - do not modify//GEN-BEGIN:variables
  private javax.swing.JPanel inner;
  private javax.swing.JLabel jLabel1;
  private javax.swing.JLabel lb_logs;
  private javax.swing.JLabel lb_logsResults;
  private javax.swing.JLabel lb_screenhsots;
  private javax.swing.JLabel lb_screenshotsResults;
  private javax.swing.JLabel lb_torrents;
  private javax.swing.JLabel lb_torrentsResults;
  private myComponents.myGUI.buttons.MyButtonCancel myButtonCancel1;
  private javax.swing.JPanel outer;
  // End of variables declaration//GEN-END:variables

  private void getResults() {
    for (Iterator<HouseKeepFile> it = k.deleted.iterator(); it.hasNext();) {
      HouseKeepFile houseKeepFile = it.next();
      switch (houseKeepFile.type) {
        case HouseKeepFile.TORRENT:
          torrentsDel++;
          break;
        case HouseKeepFile.LOG:
          logsDel++;
          break;
        case HouseKeepFile.SCREENSHOT:
          screenshotsDel++;
          break;
      }
    }
    for (Iterator<HouseKeepFile> it = k.notDeleted.iterator(); it.hasNext();) {
      HouseKeepFile houseKeepFile = it.next();
      switch (houseKeepFile.type) {
        case HouseKeepFile.TORRENT:
          torrentsNotDel++;
          break;
        case HouseKeepFile.LOG:
          logsNotDel++;
          break;
        case HouseKeepFile.SCREENSHOT:
          screenshotsNotDel++;
          break;
      }
    }
  }

  private void showResults() {
    lb_torrentsResults.setText(torrentsDel + " / " + (torrentsNotDel + torrentsDel));
    lb_logsResults.setText(logsDel + " / " + (logsNotDel+logsDel));
    lb_screenshotsResults.setText(screenshotsDel + " / " + (screenshotsNotDel + screenshotsDel ));
  }
}
